package lumis.content.control.button;

import lumis.doui.control.button.AutoAdministrationListButtonsControl;
import lumis.portal.PortalException;
import lumis.util.XmlUtil;

/**
 * Responsible for including versions and preview buttons.
 * Detects and automatically adds the following controls: lum_interfaceHeaderButtons, lum_addButton, lum_editButton, lum_deleteButton, lum_versionsButton, lum_previewButton, lum_configureButton.  
 * This control is suitable for use with content sources.
 * <br/><br/>							
 * If all buttons are detected the following subcontrols are created:
 * <br/>
 * <pre>
 * &lt;control type="lum_interfaceHeaderButtons" id="lumInterfaceHeaderButtons"&gt;
 * 	&lt;control type="lum_addButton" id="addButton" /&gt;
 * 	&lt;control type="lum_editButton" id="editButton" /&gt;
 * 	&lt;control type="lum_deleteButton" id="deleteButton" /&gt;
 * 	&lt;control type="lum_versionsButton" id="versionsButton" /&gt;
 * 	&lt;control type="lum_previewButton" id="previewButton" /&gt;
 * 	&lt;control type="lum_configureButton" id="configureButton" /&gt;
 * &lt;/control&gt;
 * </pre>
 *
 * @version $Revision: 8618 $ $Date: 2007-12-18 11:34:20 -0200 (Tue, 18 Dec 2007) $
 * @since 4.1.0
 */
public class AutoContentAdministrationListButtonsControl extends AutoAdministrationListButtonsControl
{
	@Override
	protected String appendPreConfigureButtons() throws PortalException
	{
		String editInterfaceId = XmlUtil.readAttributeString("editInterfaceId", controlDefinitionNode, "");
		
		StringBuilder appendButtons = new StringBuilder();

		appendButtons.append(super.appendPreConfigureButtons());
		
		if (XmlUtil.selectSingleNode("fields/field[@isVersionActive='true']", getSource().getDefinitionNode()) != null)
			appendButtons.append("<control type=\"lum_versionsButton\" id=\"versionsButton\" editInterfaceId=\"" + editInterfaceId + "\"/>");
		
		appendButtons.append("<control type=\"lum_previewButton\" id=\"previewButton\" />");
		
		return appendButtons.toString();
	}
}
